
from datetime import datetime
from typing import Optional
from core.commons import Gender
from sqlmodel import Field, Relationship, SQLModel


class DriverBase(SQLModel):
    bank_card_number:str = Field(default=...,max_length=30,unique=True,index=True,title="银行卡号")
    license_plate: str = Field(default=...,index=True,unique=True,max_length=18,title="司机编码")
    gender:Gender = Field(default=Gender.UNKNOWN,title="性别")
    idcard:str  = Field(default=...,min_length=16,max_length=20,unique=True,index=True,title="身份证号")
    phone:str = Field(default=...,max_length=11,unique=True,index=True,title="手机号")
    bank_name:str = Field(default=...,max_length=100,title="开户行名称")
    create_at: datetime = Field(default=datetime.now(),title="创建时间")
    update_at: Optional[datetime] = Field(default=None,title="创建时间")

class Driver(DriverBase,table=True):
    id: int = Field(default=None, primary_key=True,title="自增主键id")
    full_name: str = Field(default=...,index=True,title="姓名")
    user_id: Optional[int] = Field(default=None,foreign_key="users.id",unique=True,title="用户id")
    order_initial_list: list["OrderInitial"] = Relationship(back_populates="driver")
